//
//  ZYLAuthorModel.m
//  Cartoon
//
//  Created by dllo on 15/7/14.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "ZYLAuthorModel.h"
#import "AFNetworkHandler.h"
#import "ZYLAuthorTopicModel.h"
@implementation ZYLAuthorModel

- (void)dealloc
{
    [_authoravatar_url release];
    [_authorid release];
    [_authorintro release];
    [_authornickname release];
    [_authortopics release];
    [super dealloc];
}
+ (void)authorWithURLAndAuthorId:(NSNumber *)authorId block:(void (^)(ZYLAuthorModel *))block
{
    NSString *str = [NSString stringWithFormat:@"http://api.kuaikanmanhua.com/v1/users/%@", authorId];
//    NSLog(@"%@", str);
    [AFNetworkHandler GETwithAFNByURL:str completion:^(id result) {
        ZYLAuthorModel *authormodel = [[[ZYLAuthorModel alloc] initWithDic:result[@"data"]] autorelease];
        NSArray *arr = result[@"data"][@"topics"];
        authormodel.authortopics  = [NSMutableArray array];
        for (NSDictionary *dic in arr) {
            ZYLAuthorTopicModel *topicmodel = [[ZYLAuthorTopicModel alloc] initWithDic:dic];
            [authormodel.authortopics addObject:topicmodel];
            [topicmodel release];
        }
        block(authormodel);
    }];
}

- (instancetype)initWithDic:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        self.authortopics = [NSMutableArray array];
        [self setValuesForKeysWithDictionary:dic];
    }
    return self;
}
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
}
- (id)valueForUndefinedKey:(NSString *)key
{
    return nil;
}
- (void)setValue:(id)value forKey:(NSString *)key
{
    [super setValue:value forKey:[NSString stringWithFormat:@"author%@", key]];
}

@end
